package com.shop.thread.thread;

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

public class LRUTest {

    private static int cacheSize = 16;
    private static LinkedHashMap<String,String> linkedHashMap = null;

    public static void main(String[] args) {

        System.out.println(16 << 1);
        //LRU();
        long startTime = System.currentTimeMillis();
        ArrayList<String> list = new ArrayList<>();
        for (int i = 0 ; i < 100000; i++){
            String s = String.valueOf(i);
            list.add(s);
        }
        long endTime = System.currentTimeMillis();

        System.out.println(endTime - startTime);

        long startTime2 = System.currentTimeMillis();
        HashMap<String,String> hashMap = new HashMap<>();
        for (int i = 0 ; i< 100000; i++){
            String s = String.valueOf(i);
            hashMap.put(s,s);
        }
        long endTime2 = System.currentTimeMillis();

        System.out.println(endTime2 - startTime2);

        System.out.println(Integer.MAX_VALUE);

        Set<String> set = new HashSet<>();
        ConcurrentHashMap<String,String> concurrentMap = new ConcurrentHashMap<>();

        concurrentMap.put("","");

        HashMap<String,String> hashMap1 = new HashMap<>();
        hashMap1.put("","");

    }

    public static void LRU() {
        linkedHashMap = new LinkedHashMap<String,String>(16,0.75f,true){
            @Override
            protected boolean removeEldestEntry(Map.Entry eldest) {
                return cacheSize == linkedHashMap.size();
            }
        };


        for (int i = 0; i < 16; i++) {
            linkedHashMap.put(String.valueOf(i),String.valueOf(i));
        }

        linkedHashMap.get("2");
        linkedHashMap.put("17","17");
        linkedHashMap.put("18","18");

        linkedHashMap.entrySet().forEach(System.out::println);


    }
}
